package com.emmy.walnut.custom;

import com.emmy.walnut.constant.AppConstant;
import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.formatter.ValueFormatter;

/**
 * @ClassName weekValueFormatter
 * @Description TODO
 * @Author zhouxuan
 * @Date 2020/02/07 11:38
 * @Version 1.0
 */
public class MonthValueFormatter extends ValueFormatter {

    private final BarLineChartBase<?> chart;

    public MonthValueFormatter(BarLineChartBase<?> chart) {
        this.chart = chart;
    }

    @Override
    public String getFormattedValue(float value) {

        int index = (int) value;
        return getDayInMonth(index);

    }

    private String getDayInMonth(int index){

        index++;

        String appendix = "th";

        switch (index) {
            case 1:
                appendix = "st";
                break;
            case 2:
                appendix = "nd";
                break;
            case 3:
                appendix = "rd";
                break;
            case 21:
                appendix = "st";
                break;
            case 22:
                appendix = "nd";
                break;
            case 23:
                appendix = "rd";
                break;
            case 31:
                appendix = "st";
                break;
        }
        return index + appendix;
    }

    private String getMonthInYear(int index){
        return AppConstant.month[index];
    }
}
